<!-- 考勤统计 -->
<template>
  <vxe-grid
    ref="xTable"
    border
    resizable
    keep-source
    height="400"
    :loading="loading"
    :toolbar-config="tableToolbar"
    :edit-rules="validRules"
    :columns="tableColumn"
    :data="tableData"
    @checkbox-change="({records}) =>  this.selectedRow = records"
    :edit-config="{trigger: 'click', mode: 'row', showStatus: true}"
  >
    <template v-slot:toolbar_buttons>
      <a-button type="primary" icon="plus" style="margin:0px 8px 0px 0px;" @click="handleAdd">新增</a-button>
      <a-dropdown v-if="selectedRow.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" />删除</a-menu-item>
        </a-menu>
        <a-button>批量操作<a-icon type="down" /></a-button>
      </a-dropdown>
    </template>
  </vxe-grid>
</template>
<script >
import moment from 'moment'
import { getAction } from '@/api/manage'
import JSelectUserByDep from '@/components/jeecgbiz/JSelectUserByDep'
export default {
  name:'SalaryTemplateItemTable',
  components: {
    JSelectUserByDep
  },
  props:{
    templateCode:{
      type:String,
      default:''
    }
  },
  data() {
    return {
      loading:false,
      tableToolbar: {
        print: true,
        zoom: true,
        slots: {
          buttons: 'toolbar_buttons'
        }
      },
      tableColumn: [
        { type: 'checkbox', width: 50 },
        { type: 'seq', width: 60 },
        { field: 'salaryItemCode', title: '薪资构成', editRender: { name: '$select', options: [] }},
        { field: '1', title: '计算方式'},
        { field: 'upperLimit', title: '金额上限',editRender: { name: '$input', props: { type: 'number' } }},
        { field: 'lowerLimit', title: '金额下限', editRender: { name: '$input', props: { type: 'number' } }  },
        { field: 'remark', title: '备注' ,editRender: { name: '$input' }}
      ],
      validRules: {
        upperLimit: [
          { required: true, message: '请填写金额上限' }
        ],
        lowerLimit: [
          { required: true, message: '请填写金额下限' }
        ]
      },
      selectedRow:[],
      tableData:[],
      url:{
        list:'/hr/salary/template/listSalaryTemplateDetailByTemplateCode'
      }
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    loadData() {
      // 加载数据 若传入参数1则加载第一页的内容
      if(!this.templateCode){
        this.tableData = []
        return false
      }
      this.loading = true
      getAction(this.url.list, {templateCode:this.templateCode}).then(res => {
        if(res.success){
          this.tableData = res.result.records
        }else{
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    handleEdit(data){
      this.$refs.salaryUserModal.edit()
    },
    handleAdd(data){
      this.$refs.xTable.insert({templateCode:this.templateCode})
    },
    batchDel(){
      this.$refs.xTable.removeCheckboxRow()
    },
    validate(){
      return this.$refs.xTable.validate()
    },
    getTableData(){
      return this.$refs.xTable.getTableData()
    }
  }
}
</script>
